<template>
  <div>
    <el-card style="width: 50%">
      <div slot="header" class="clearfix">
        <span>修改用户密码</span>
      </div>

    <div class="text item">
    
  
      <el-form :model="user" label-width="80px" style="padding-right: 20px" :rules="rules">
        <el-form-item label="用户名" prop="username">
          <el-input type="text" v-model="user.username" placeholder="" disabled></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="newpassword">
          <el-input type="password" placeholder="请输入密码" v-model="user.newpassword" show-password></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="doSubmit()"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    </el-card>
  </div>
</template>

<script>
export default {
  name: "TUpdatePwd",
  data() {
    return {
     
      user: JSON.parse(localStorage.getItem("honey-user") || "{}"),
      rules: {
        
          newpassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 5, max: 15, message: '长度在 5 到 15 个字符', trigger: 'blur' }
          ]
      }
    };
  },
  created() {

  },
  methods: {
     doSubmit(){
      this.user.password = this.user.newpassword;

      this.$request.put('/teachers', this.user).then((res) => {
        console.log(res);

         if (res.code === 1) {//判断success是否为true
          // 为true给一个提示框
          console.log("data=:" + res.data);
          
          this.$router.push('/teacherLogin');
        
          this.$message({
            //message: '修改密码成功',
            message:res.msg,
            type: 'success'
          });
        } else {
          this.$message({
            //message: '修改密码失败',
            message: res.msg,
            type: 'warning'
          });
        }

      }).catch((err) => {
        console.log(err);
      });
    }

  },
};
</script>

<style>
</style>